
import 'package:flutter/material.dart';
import 'package:ls_work/routers/fluro_navigator.dart';
import 'package:ls_work/util/utils.dart';
import 'package:ls_work/widgets/progress_dialog.dart';

 class SVProgressHUD {
  bool _isShowDialog = false;
  final BuildContext context;
  SVProgressHUD(this.context);

  void closeProgress() {
    if (_isShowDialog) {
      _isShowDialog = false;
      NavigatorUtils.goBack(context);
    }
  }

  void showProgress({String hint = "正在加载..."}) {
    /// 避免重复弹出
    if (!_isShowDialog) {
      _isShowDialog = true;
      try {
         showTransparentDialog(
            context: context,
            barrierDismissible: false,
            builder: (_) {
              return WillPopScope(
                onWillPop: () async {
                  // 拦截到返回键，证明dialog被手动关闭
                  _isShowDialog = false;
                  return Future.value(true);
                },
                child:  ProgressDialog(hintText: hint),
              );
            });
      } catch (e) {
        /// 异常原因主要是页面没有build完成就调用Progress。
        print(e);
      }
    }
  }
}




